package com.zbl.zblproject.erp.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/12/10
 * 财务审核日志
 */
@TableName("zbl_finance_log")
public class ErpFinanceLog {

    /**
     * 自定义收款
     */
    public static final int MODE_CUSTOMIZE_PAYMENT = 3;

    /**
     * 自定义付款
     */
    public static final int MODE_CUSTOMIZE_RECEIPT = 2;

    /**
     * 收款
     */
    public static final int MODE_PAYMENT = 1;

    /**
     * 付款
     */
    public static final int MODE_RECEIPT = 0;

    @TableId(type = IdType.AUTO)
    private int id;

    private String storeName;

    /**
     * 操作人名称
     */
    private String operator;

    /**
     * 创建人名称
     */
    private String creater;

    /**
     * 付款人
     */
    private String payer;

    /**
     * 收/付款单号
     */
    private String orderNumber;

    /**
     * 首付款模式
     */
    private int mode;


    /**
     * 订单号
     */
    private String orderSn;

    /**
     * 收款金额
     */
    private BigDecimal total;

    /**
     * 备注
     */
    private String remark;

    /**
     * 状态
     */
    private int status;

    private LocalDateTime checktime;

    /**
     * 返点,回扣
     */
    private BigDecimal rebate;

    /**
     * 返点率
     */
    private BigDecimal rebateRate;

    /**
     * 凭证图片
     */
    private String imgPath;

    /**
     * 用户之前余额
     */
    private BigDecimal userBalance;

    /**
     * 欠货金额
     */
    private BigDecimal owedMoney;

    /**
     * 退货金额
     */
    private BigDecimal returnMoney;

    /**
     * 抹零金额
     */
    private BigDecimal zeroMoney;

    /**
     * 备注
     */
    private String context;

    /**
     * 已支付
     */
    private BigDecimal paid;

    private String supplierName;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getOrderSn() {
        return orderSn;
    }

    public void setOrderSn(String orderSn) {
        this.orderSn = orderSn;
    }

    public BigDecimal getTotal() {
        return total;
    }

    public void setTotal(BigDecimal total) {
        this.total = total;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public LocalDateTime getChecktime() {
        return checktime;
    }

    public void setChecktime(LocalDateTime checktime) {
        this.checktime = checktime;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public int getMode() {
        return mode;
    }

    public void setMode(int mode) {
        this.mode = mode;
    }

    public BigDecimal getRebate() {
        return rebate;
    }

    public void setRebate(BigDecimal rebate) {
        this.rebate = rebate;
    }

    public String getFormatTotal(){
        if(total == null){
            return "0.00";
        }
        DecimalFormat df = new DecimalFormat("#0.00");
        return df.format(total);
    }

    public String getFormatRebate(){
        if(rebate == null){
            return "0.00";
        }
        DecimalFormat df = new DecimalFormat("#0.00");
        return df.format(rebate);
    }

    public BigDecimal getUserBalance() {
        return userBalance;
    }

    public void setUserBalance(BigDecimal userBalance) {
        this.userBalance = userBalance;
    }


    public BigDecimal getSubTotal(){
        BigDecimal to = Optional.ofNullable(total).orElse(BigDecimal.ZERO);
        BigDecimal ret = Optional.ofNullable(returnMoney).orElse(BigDecimal.ZERO);
        BigDecimal owed = Optional.ofNullable(owedMoney).orElse(BigDecimal.ZERO);
        return to.subtract(ret).subtract(owed);
    }

    /**
     * 实收
     * @return
     */
    public String  getRealTotal(){
        BigDecimal to = Optional.ofNullable(total).orElse(BigDecimal.ZERO);
        BigDecimal re = Optional.ofNullable(rebate).orElse(BigDecimal.ZERO);
        BigDecimal ret = Optional.ofNullable(returnMoney).orElse(BigDecimal.ZERO);
        BigDecimal owed = Optional.ofNullable(owedMoney).orElse(BigDecimal.ZERO);
        BigDecimal real = to.subtract(re).subtract(ret).subtract(owed);
        DecimalFormat df = new DecimalFormat("#0.00");
        return df.format(real);
    }

    public BigDecimal  getRealPrice(){
        BigDecimal to = Optional.ofNullable(total).orElse(BigDecimal.ZERO);
        BigDecimal re = Optional.ofNullable(rebate).orElse(BigDecimal.ZERO);
        BigDecimal ret = Optional.ofNullable(returnMoney).orElse(BigDecimal.ZERO);
        BigDecimal owed = Optional.ofNullable(owedMoney).orElse(BigDecimal.ZERO);
        BigDecimal zero = Optional.ofNullable(zeroMoney).orElse(BigDecimal.ZERO);
        BigDecimal real = to.subtract(re).subtract(ret).subtract(owed).subtract(zero);
        return real;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }

    public String getContext() {
        return context;
    }

    public void setContext(String context) {
        this.context = context;
        this.remark = context;
    }

    public BigDecimal getOwedMoney() {
        return owedMoney;
    }

    public void setOwedMoney(BigDecimal owedMoney) {
        this.owedMoney = owedMoney;
    }

    public BigDecimal getReturnMoney() {
        return returnMoney;
    }

    public void setReturnMoney(BigDecimal returnMoney) {
        this.returnMoney = returnMoney;
    }

    public BigDecimal getZeroMoney() {
        return zeroMoney;
    }

    public void setZeroMoney(BigDecimal zeroMoney) {
        this.zeroMoney = zeroMoney;
    }

    public static int getModePayment() {
        return MODE_PAYMENT;
    }

    public static int getModeReceipt() {
        return MODE_RECEIPT;
    }

    public BigDecimal getRebateRate() {
        return rebateRate;
    }

    public void setRebateRate(BigDecimal rebateRate) {
        this.rebateRate = rebateRate;
    }

    public static int getModeCustomizePayment() {
        return MODE_CUSTOMIZE_PAYMENT;
    }

    public static int getModeCustomizeReceipt() {
        return MODE_CUSTOMIZE_RECEIPT;
    }

    public BigDecimal getPaid() {
        return paid;
    }

    public void setPaid(BigDecimal paid) {
        this.paid = paid;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }


    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String getPayer() {
        return payer;
    }

    public void setPayer(String payer) {
        this.payer = payer;
    }

    @Override
    public String toString() {
        return "ErpFinanceLog{" +
                "id=" + id +
                ", orderSn='" + orderSn + '\'' +
                ", total=" + total +
                ", remark='" + remark + '\'' +
                '}';
    }

    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }
}
